home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / USeqPrint-remap.cpp < prev    next >
Text File  |  1996-07-05  |  42KB  |  1,560 lines

  1. // USeqPrint.remap.p 
  2. // d.g.gilbert, 1991 
  3.  
  4. /*
  5.         restrict map print
  6. */
  7.     
  8. #pragma segment Remap
  9.  
  10.  
  11. CONST
  12.     kREMapWindowRSRCID == 1022;
  13.  
  14.  
  15.  
  16. // TREMapDocument -----------------------------------------------
  17.  
  18.  
  19. pascal void TREMapDocument::IREMapDocument(OSType fileType, TDocument parentDoc, 
  20.                                                     TSequence        aSeq; longint startbase, nbases)
  21. VAR  aFile: TFile;
  22. {
  23.     fREMapView= NULL;
  24.     fSeq= NULL;
  25.     fParentDoc= parentDoc;
  26.     FailNIL( aSeq);
  27.     fSeq= TSequence(aSeq->Clone());
  28.     if (nbases<1) fSeq->GetSelection( startbase,nbases);
  29.     fFirstBase= startBase;
  30.     fNBases= nbases;
  31.     
  32.     /*---
  33.     New(aFile);
  34.     aFile->IFile(...);
  35.     aname= parentDoc.name + '.dotplot';
  36.     vol= parentdoc.vol;
  37.     dirid= parentdoc.dirid;
  38.     err= aFile->SpecifyWithTrio( name/vol/dirid);
  39.     ----*/
  40.     aFile= NewFile(fileType, kSAppSig, kUsesDataFork, kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
  41.     IFileBasedDocument( aFile, fileType);
  42.     fSavePrintInfo = FALSE; //was TRUE;
  43. }
  44.  
  45. pascal TFile TREMapDocument::DoMakeFile(itsCommandNumber:CommandNumber); // override 
  46. {
  47.     DoMakeFile= NewFile(fScrapType, gApplication->fCreator, kUsesDataFork, kUsesRsrcFork, 
  48.                                                 !kDataOpen, !kRsrcOpen);
  49. }
  50.  
  51. pascal void TREMapDocument::FreeData(void)
  52. {
  53.     if (fSeq!=NULL)    fSeq->Free(); fSeq= NULL;
  54.     //-- !?!?! fREMapView.free should be done automatically by superview.free
  55.     //- if ((fREMapView!=NULL)) fREMapView->Free();  fREMapView= NULL; 
  56. }
  57.  
  58.  
  59. pascal void TREMapDocument::Free(void) // override 
  60. {
  61.     FreeData();
  62.     inherited::Free();
  63. }
  64.  
  65.  
  66. pascal void TREMapDocument::Close(void) /* override */ 
  67. {
  68.         /* patches for prefwindow */        
  69.     if ((fREMapView->fUseColor) && (fColorButton!=NULL)) fColorButton->fHilite= TRUE;
  70.     this->SetChangeCount(0); //so we don't always get Save? yes/no/canc dlog 
  71.   inherited::Close();
  72. }
  73.  
  74.  
  75.  
  76. pascal void TREMapDocument::DoMakeViews(Boolean forPrinting) // override 
  77. VAR
  78.         aWindow    : TWindow;
  79.         minSize    : Point;
  80.         maxSize    : Point;
  81.         vSize     : Vpoint;
  82. {
  83.     aWindow = gViewServer->NewTemplateWindow(/*!*/kREMapWindowRSRCID, this);
  84.     FailNil(aWindow);
  85.     
  86.     fREMapWind = TREMapWind(aWindow);
  87.     fREMapWind->IREMapWind();
  88.     fREMapWind->fRedrawBut= TButton(aWindow->FindSubView('bRDR'));
  89.     
  90.     fREMapView = TREMapView(aWindow->FindSubView('PrVw'));
  91.     FailNil(fREMapView);
  92.     fREMapView->InstallControls();
  93.  
  94.     fColorButton= TIcon(aWindow->FindSubView('iClr'));
  95.     fColorButton->fEventNumber= mColorButHit;
  96.     fMonoButton = TIcon(aWindow->FindSubView('iB&W'));
  97.     fMonoButton->fEventNumber= mMonoButHit;
  98.     fREMapView->fUseColor= fColorButton->fHilite;  
  99.     fColorButton->fHilite= FALSE;
  100.     fMonoButton->fHilite= FALSE;
  101.     if (!gConfiguration.hasColorQD) {
  102.         fColorButton->ViewEnable(FALSE, kDontRedraw);
  103.         fColorButton->Show(FALSE, kDontRedraw);
  104.         fMonoButton->ViewEnable(FALSE, kDontRedraw);
  105.         fMonoButton->Show(FALSE, kDontRedraw);
  106.         fREMapView->fUseColor    = FALSE;
  107.         }
  108.     
  109.         // get our damn data into view 
  110.     /*!*/ 
  111.     fREMapView->AddSeqs();
  112.     fREMapView->SetDrawOptions();
  113.     
  114.     // set window's resize limits so it can't become wider than the REMapview's edge 
  115.     WITH aWindow->fResizeLimits){
  116.         minSize = topLeft;
  117.         maxSize = botRight;
  118.         }
  119.     WITH maxSize)h = Min( 2 + fREMapView->fSize.h + kSBarSizeMinus1, h);
  120.     //-- aWindow->SetResizeLimits(minSize, maxSize); << bad !!
  121.  
  122.     //?! need to show TEView in PrintView... ?
  123.     this->ShowReverted();   
  124. }
  125.  
  126.  
  127. pascal void TREMapDocument::UntitledName(Str255 VAR noName) // override 
  128. //!called AFTER .Idoc and .MakeViews 
  129. {
  130.     noName= Concat(fSeq->fName,' R.E.Map'); 
  131.     if ((fWindowList != NULL) && (fWindowList.GetSize > 0))         
  132.         TWindow(fWindowList->First())->SetTitle(noName);
  133. }
  134.  
  135.  
  136.  
  137. pascal void TREMapDocument::DoNeedDiskSpace(TFile itsFile,
  138.                                                             long VAR dataForkBytes, rsrcForkBytes)
  139. {
  140.     //)!get Print record requirements 
  141.     //- inherited::DoNeedDiskSpace(dataForkBytes, rsrcForkBytes); 
  142.     
  143.     dataForkBytes = dataForkBytes + kMacdrawHeaderSize  /*+ sizeof window pict */;
  144.     
  145.     /*-- if you really want to know pict size:
  146.     fREMapView->WriteToDeskScrap(); 
  147.     len= fREMapView->GivePasteData( NULL, 'PICT');
  148.     rsrcForkBytes = rsrcForkBytes + kRsrcTypeOverhead + kRsrcOverhead + sizeof(DocState);
  149.     ---*/
  150. }
  151.  
  152.  
  153. pascal void TREMapDocument::DoRead(aFile:TFile; Boolean forPrinting)
  154. {
  155.     //-- inherited::DoRead(aRefNum, rsrcExists, forPrinting);)!read print info stuff
  156.     // This is a Write-Only document == PICT of output drawing, no reading... ?
  157. }
  158.  
  159.  
  160. pascal void TREMapDocument::DoWrite(TFile aFile, Boolean makingCopy)
  161. VAR
  162.         longint        len, count;
  163.         hPict            : handle;
  164.         header        : packed array [1..kMacdrawHeaderSize] of char;
  165.         fi                : FailInfo;
  166.  
  167.     pascal void HdlDoWrite(OSErr error, long message)
  168.     {
  169.         if (hPict != NULL) DisposHandle( hPict);
  170.     }
  171.  
  172. {
  173.     //- inherited::DoWrite(aRefNum, makingCopy);     --)NO write print info stuff
  174.  
  175.     fREMapView->WriteToDeskScrap();
  176.     
  177.     hPict= NewHandle(0);
  178.     CatchFailures(fi, HdlDoWrite);
  179.     len= fREMapView->GivePasteData( hPict, 'PICT');
  180.     if ((len > 0)) {
  181.         fillchar(header, kMacdrawHeaderSize, ((char)(0)));  
  182.         count = kMacdrawHeaderSize;
  183.         FailOSErr( aFile->WriteData( &header, count));
  184.         count= len;
  185.         HLock(hPict);
  186.         FailOSErr( aFile->WriteData( ptr((*hPict)), count));
  187.         HUnlock(hPict);    
  188.         }
  189.     Success(fi);
  190.     DisposHandle( hPict);
  191. }
  192.  
  193.  
  194.  
  195.  
  196. // TREMapWind ------------------------- 
  197.  
  198. pascal void TREMapWind::IREMapWind(void)
  199. {
  200.     IPrefWindow();
  201.     fWantSave= TRUE;
  202. }
  203.  
  204. pascal void TREMapWind::SetPrefID(void) /* override */ 
  205. {
  206.     gPrefWindID= kREMapWindowRSRCID; gPrefWindName= 'TREMapWind';
  207. }
  208.  
  209.  
  210. pascal void TREMapWind::DoEvent(EventNumber eventNumber, 
  211.                                             TEventHandler        source; TEvent event) // override 
  212. VAR
  213.         TREMapView        aREMapView;
  214.  
  215. {
  216.     aREMapView= TREMapDocument(fDocument).fREMapView;
  217.     //- aREMapView->SetDrawOptions();
  218.  
  219.     switch (eventNumber) {
  220.         mColorButHit: {
  221.                 aREMapView->fUseColor= TRUE;
  222.                 aREMapView->ForceRedraw();
  223.                 }
  224.         mMonoButHit: {
  225.                 aREMapView->fUseColor= FALSE;
  226.                 aREMapView->ForceRedraw();
  227.                 }
  228.         mButtonHit: if ((source == fRedrawBut)) {
  229.                 aREMapView->SetDrawOptions();
  230.                 aREMapView->ForceRedraw();
  231.                 }            else 
  232.                 inherited::DoEvent(eventNumber,source, event); 
  233.  
  234.         otherwise
  235.                 inherited::DoEvent(eventNumber,source, event); 
  236.         }
  237. }
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. // TREMapView -------------------------------------
  245.  
  246.  
  247. pascal void TREMapView::Free(void) // override 
  248. {
  249.     TObject(fREMap)= FreeIfObject(fREMap);
  250.     Handle(fProt)= DisposeIfHandle(fProt);
  251.     Handle(fCoProt)= DisposeIfHandle(fCoProt);
  252.     inherited::Free();
  253. }
  254.  
  255.  
  256. pascal void TREMapView::Initialize(void) // override 
  257. //called by IObject/via IView...
  258. CONST
  259.     //- kBasesPerLine == 40;
  260.     kTenSpacer     == 10;
  261. {
  262.     inherited::Initialize();
  263.  
  264.     fREMapDocument= NULL;
  265.     fSeq= NULL;
  266.     fFirstBase= 0;
  267.     fNbases= 0;
  268.     
  269.     fStyleName= NULL;
  270.     fStyleBase= NULL;
  271.     fStyleNums= NULL;
  272.     fUseColor= TRUE;
  273.     fDoTopIndex= TRUE;
  274.     fDoLeftIndex= FALSE;
  275.     fDoRightIndex= FALSE;
  276.     fDoLeftName= TRUE;
  277.     fDoRightName= FALSE;
  278.     fBasesPerLine= kBasesPerLine;
  279.     fTenSpacer= kTenSpacer;
  280.     fNameWidth= kMaxNameWidth;
  281.     fIndexWidth= kMaxNameWidth;
  282.     
  283.     //! new for REMap.............
  284.     fSeqRowHeight= 20;
  285.     fLastZymeCut= 1;
  286.     fREMap= NULL;
  287.     fProt= NULL;
  288.     fCoProt= NULL;
  289.     
  290.     fNoncutters= NULL;
  291.     fCutpoints= NULL;
  292.     fAllzymes= NULL;
  293.     fShowCoseq= NULL;
  294.     fShowindex= NULL;
  295.     fMincuts= NULL;
  296.     fMaxcuts= NULL;
  297.             
  298.     fAllZymesStart= 0;
  299.     fAllZymesEnd= 0;
  300.     fNoCutsStart= 0;
  301.     fNoCutsEnd= 0;
  302.     fCutPointStart= 0;
  303.     fCutPointEnd= 0;
  304.  
  305. }
  306.  
  307.  
  308. pascal void TREMapView::IREMapView( TREMapDocument itsDocument, Boolean forClipboard)
  309. VAR
  310.         itsSize        : VPoint;
  311.         aHandler    : TStdPrintHandler;
  312.         sd                : SizeDeterminer;
  313. {
  314.     fREMapDocument = TREMapDocument(itsDocument);
  315.     fFirstBase= fREMapDocument->fFirstBase;  
  316.     fNbases= fREMapDocument->fNbases;  
  317.     fSeq= fREMapDocument->fSeq;  
  318.     
  319.     SetVPt(itsSize, kMaxCoord, kMaxCoord);
  320.     if (forClipboard)
  321.         sd = sizeVariable
  322.     else
  323.         sd = sizeFillPages;
  324.     //- IView(itsDocument, NULL, gZeroVPt, itsSize, sd, sd); 
  325.     IGridView( itsDocument, NULL, gZeroVPt, itsSize, sd, sd, 10, 50, 20, 20, 
  326.                                                     FALSE, FALSE, 0, 0, FALSE);
  327.  
  328. #if FALSE                                        //!!! Need to handle this
  329.     if (forClipboard) fWouldMakePICTScrap = TRUE;
  330. #endif
  331.     if (!forClipboard) {
  332.         New(aHandler);
  333.         FailNil(aHandler);
  334.         aHandler->IStdPrintHandler(itsDocument, this, !kSquareDots, kFixedSize, kFixedSize);         
  335.         }
  336. }
  337.  
  338.  
  339.  
  340. pascal void TREMapView::DoPostCreate(TDocument itsDocument) // override 
  341. VAR  aHandler: TStdPrintHandler;
  342. {
  343.     inherited::DoPostCreate( itsDocument);
  344.     fREMapDocument= TREMapDocument(itsDocument);
  345.     fFirstBase= fREMapDocument->fFirstBase;  
  346.     fNbases= fREMapDocument->fNbases;  
  347.     fSeq= fREMapDocument->fSeq;  
  348.     New(aHandler);
  349.     FailNil(aHandler);
  350.     aHandler->IStdPrintHandler(itsDocument, this, !kSquareDots, kFixedSize, kFixedSize);     
  351. }
  352.  
  353. pascal void TREMapView::AddSeqs(void)
  354. VAR
  355.         atRow, i     : integer;
  356.         GridCell        c1, c2 ;
  357.         h            : Handle;
  358.         nums    : Str255;
  359.         nb        : longint;
  360.         pc        : CharsPtr;
  361. {    
  362.     fREMap= TREMap(gREMap->Clone()); //duplicate master w/ re lists
  363.     fREMap->MapSeq( fSeq);
  364.     fCutList= fREMap->fSeqCuts; //copy for easy use
  365.     
  366.     if (fNbases<1) then nb= GetHandleSize(fSeq->fBases)
  367.     else nb= fNbases;
  368.     pc= CharsPtr(fSeq.(*fBases));
  369.     pc= &(*pc)[fFirstBase];
  370.     fProt= Nucleic23Protein( pc, nb);
  371.     pc= CharsPtr(fREMap->fCoSeq.(*fBases));
  372.     pc= &(*pc)[fFirstBase];
  373.     fCoProt= Nucleic23Protein( pc, nb);
  374. }
  375.  
  376. pascal void TREMapView::InstallControls(void)
  377. VAR  aWindow    : TWindow;
  378. {
  379.     aWindow= GetWindow;
  380.     
  381.     fTopIndex    = TCheckBox(aWindow->FindSubView('cTop'));
  382.     fLeftIndex= TCheckBox(aWindow->FindSubView('cLft'));
  383.     fRightIndex= TCheckBox(aWindow->FindSubView('cRgt'));
  384.     fLeftName    = TCheckBox(aWindow->FindSubView('nLft'));
  385.     fRightName= TCheckBox(aWindow->FindSubView('nRgt'));
  386.     
  387.     fStyleName= TDlogTextView(aWindow->FindSubView('tNam'));
  388.     fStyleBase= TDlogTextView(aWindow->FindSubView('tBas'));
  389.     fStyleNums= TDlogTextView(aWindow->FindSubView('tNum'));
  390.  
  391.     if (fStyleName!=NULL) fStyleName->SetText('Names');
  392.     if (fStyleBase!=NULL) fStyleBase->SetText('Bases');
  393.     if (fStyleNums!=NULL) fStyleNums->SetText('Index');
  394.     
  395.         //!--- added for REMap ---
  396.     fNoncutters= TCheckBox(aWindow->FindSubView('cNOC'));
  397.     fCutpoints= TCheckBox(aWindow->FindSubView('cCUT'));
  398.     fAllzymes= TCheckBox(aWindow->FindSubView('cALL'));
  399.     fShowCoseq= TCheckBox(aWindow->FindSubView('cCOS'));
  400.     fMincuts = TNumberText(aWindow->FindSubView('nMIN'));
  401.     fMaxcuts = TNumberText(aWindow->FindSubView('nMAX'));
  402.  
  403.     fSeqFrame1= TCheckBox(aWindow->FindSubView('cSF1'));
  404.     fSeqFrame2= TCheckBox(aWindow->FindSubView('cSF2'));
  405.     fSeqFrame3= TCheckBox(aWindow->FindSubView('cSF3'));
  406.     fCoFrame1 = TCheckBox(aWindow->FindSubView('cCF1'));
  407.     fCoFrame2 = TCheckBox(aWindow->FindSubView('cCF2'));
  408.     fCoFrame3 = TCheckBox(aWindow->FindSubView('cCF3'));
  409.     fThreeBase= TRadio(aWindow->FindSubView('r3aa'));
  410. }
  411.  
  412.  
  413. pascal void TREMapView::FindNameWidth(void)
  414. VAR    
  415.         linesPerParag, numLinesPerSeq,
  416.         allzymeRows, allzymeHeight,  
  417.         cutRows, cutHeight,
  418.         nocutsRows, nocutsHeight,
  419.         integer        maxNameWid, fontheight, maxdeep;
  420.         GrafPtr        savePort;
  421.         nums    : Str255;
  422.         longint        nlines, need, lastBase;
  423.         fi        : fontInfo;
  424.         
  425.     pascal void GetNameWidth(TSequence aSeq)
  426.     VAR  aName        : Str63;
  427.     {
  428.         if (aSeq!=NULL) {
  429.             aName= aSeq->fName;
  430.             maxNameWid= max(maxNameWid, StringWidth(aName));
  431.             } 
  432.     }
  433. {
  434.     if (fStyleName == NULL) fNameStyle= gPrintNameStyle 
  435.     else fNameStyle= fStyleName->fTextStyle;
  436.     if (fStyleBase == NULL) fBaseStyle= gPrintNucStyle 
  437.     else fBaseStyle= fStyleBase->fTextStyle;
  438.     if (fStyleNums == NULL) fNumStyle= gPrintNameStyle 
  439.     else fNumStyle= fStyleNums->fTextStyle;
  440.     maxdeep= 0;
  441.     
  442.     GetPort( savePort);
  443.     SetPort( gWorkPort);
  444.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  445.     maxNameWid= 0;
  446.     //- fAlnList->Each(GetNameWidth);
  447.     GetNameWidth( fSeq);
  448.     fNameWidth= Min( maxNameWid + kNucBorder, kMaxNameWidth); 
  449.     GetFontInfo(fi);
  450.     fontheight= fi.ascent+fi.descent+fi.leading;
  451.     maxdeep= Max(maxdeep, fontheight);
  452.     
  453.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  454.     lastBase= fFirstBase + fNBases;
  455.     NumToString( lastBase, nums);
  456.     fIndexWidth= StringWidth(nums) + kNucBorder;
  457.     GetFontInfo(fi);
  458.     fontheight= fi.ascent+fi.descent+fi.leading;
  459.     maxdeep= Max(maxdeep, fontheight);
  460.     
  461.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fBaseStyle);  /*$POP
  462.     fBaseWidth= CharWidth('G') + kNucSpace;
  463.     GetFontInfo(fi);
  464.     fontheight= fi.ascent+fi.descent+fi.leading;
  465.     maxdeep= Max(maxdeep, fontheight);
  466.     
  467.         //fix grid size: 
  468.     need= (fBasesPerLine+4) - fNumOfCols;
  469.     if ((need>0))  InsColLast( need, fBaseWidth)
  470.     else if ((need<0)) DelColLast( -need);
  471.     
  472.     //! num of rows == numLinesPerSeq, BUT each row may have different width !!
  473.     //! add one header line at top?
  474.     numLinesPerSeq= (fBasesPerLine - 1 + fNBases) / fBasesPerLine;
  475.     linesPerParag= 11; // spacer + 3 pro + seq + index + coseq + 3copro + renzymes 
  476.     
  477.     fSeqRowHeight= maxdeep;
  478.     nlines= 1 + numLinesPerSeq * linesPerParag; //header + sequence
  479.  
  480. /*****
  481.     this->AllZymeTabRows( allzymeRows, allzymeHeight);
  482.     fAllZymesStart= nlines+1;
  483.     fAllZymesEnd= fAllZymesStart + allzymeRows-1;
  484.     nlines= fAllZymesEnd;  //allzyme table
  485.  
  486.     this->NocuttersRows( nocutsRows, nocutsHeight); //!! BAD if nocutsRows != 0 !!!!!!!!!
  487.     fNoCutsStart= nlines+1;
  488.     fNoCutsEnd= fNoCutsStart + nocutsRows-1;
  489.     nlines= fNoCutsEnd;  //nocutters table
  490.  
  491.     this->CutpointsRows( cutRows, cutHeight);
  492.     fCutpointStart= nlines+1;
  493.     fCutpointEnd= fCutpointStart + cutRows-1;
  494.     nlines= fCutpointEnd;  //cutpoints table
  495. ******/
  496.  
  497.     nlines= nlines + 1; //footer
  498.     
  499.     need= nlines - fNumOfRows;
  500.     if ((need>0)) InsRowLast( need, fSeqRowHeight)
  501.     else if ((need<0)) DelRowLast( -need);
  502.     
  503.     SetRowHeight( 1, 1, 30+fSeqRowHeight);        //header
  504. /***
  505.     if ((allzymeRows>0)) SetRowHeight( fAllZymesStart, allzymeRows, allzymeHeight);
  506.     if ((nocutsRows>0)) SetRowHeight( fNoCutsStart, nocutsRows, nocutsHeight);
  507.     if ((cutRows>0)) SetRowHeight( fCutpointStart, cutRows, cutHeight);
  508. ***/
  509.     SetRowHeight( nlines, 1, fSeqRowHeight);     //? footer
  510.     
  511.     SetPort( savePort);
  512. }
  513.  
  514.  
  515. pascal void TREMapView::SetDrawOptions(void) 
  516. VAR        
  517.         wid, fixwid, i, atRow,
  518.         first, ncuts, maxcuts,
  519.         integer        startbase, endbase, atbase;
  520.         Integer        numLinesPerSeq, linesPerParag, theRowHeight;
  521.         allSeqFrames, allCoFrames,
  522.         noSeqFrames, noCoFrames,
  523.         doFrame1, doFrame2, doFrame3,
  524.         doCoFrame1, doCoFrame2, doCoFrame3,
  525.         Boolean        doCoSeq;
  526.         aRect    : VRect;
  527.         
  528.     pascal void SetOneRow( integer VAR atRow, Boolean optionIsOn)
  529.     integer        VAR  wid;
  530.     {
  531.         if (optionIsOn) wid= theRowHeight else wid= 0;
  532.         SetRowHeight( atRow, 1, wid); 
  533.         atRow= atRow+1;
  534.     }
  535.         
  536.  
  537.     pascal void AddTables(void)
  538.     VAR
  539.         allzymeRows, allzymeHeight,  
  540.         cutRows, cutHeight,
  541.         integer        nocutsRows, nocutsHeight ;
  542.     {
  543.         fAllZymesStart= fNumOfRows+1;
  544.         this->AllZymeTabRows( allzymeRows, allzymeHeight);
  545.         InsRowLast( allzymeRows, allzymeHeight);
  546.         fAllZymesEnd= fNumOfRows;
  547.  
  548.         fNoCutsStart= fNumOfRows+1;
  549.         this->NocuttersRows( nocutsRows, nocutsHeight);  
  550.         InsRowLast( nocutsRows, nocutsHeight);
  551.         fNoCutsEnd= fNumOfRows;
  552.     
  553.         fCutpointStart= fNumOfRows+1;
  554.         this->CutpointsRows( cutRows, cutHeight);
  555.         InsRowLast( cutRows, cutHeight);
  556.         fCutpointEnd= fNumOfRows;
  557.     }
  558.     
  559. {
  560.     FindNameWidth();
  561.     
  562.     if (fTopIndex == NULL) fDoTopIndex= TRUE else fDoTopIndex= fTopIndex->IsOn();  
  563.     if (fLeftIndex == NULL) fDoLeftIndex= FALSE else fDoLeftIndex= fLeftIndex->IsOn();  
  564.     if (fRightIndex == NULL) fDoRightIndex= FALSE else fDoRightIndex= fRightIndex->IsOn();  
  565.     if (fLeftName == NULL) fDoLeftName= FALSE else fDoLeftName= fLeftName->IsOn();  
  566.     if (fRightName == NULL) fDoRightName= FALSE else fDoRightName= fRightName->IsOn();  
  567.     
  568.     if (fDoLeftName) wid= fNameWidth else wid= 0;
  569.     this->SetColWidth( 1, 1, wid);
  570.     if (fDoLeftIndex) wid= fIndexWidth else wid= 0;
  571.     this->SetColWidth( 2, 1, wid);
  572.     
  573.     FOR i= 1 TO fBasesPerLine){
  574.         if ((i<fBasesPerLine) && (i % 10 == 0)) SetColWidth( i+2, 1, fBaseWidth+fTenSpacer)
  575.         else SetColWidth( i+2, 1, fBaseWidth);
  576.         }
  577.     
  578.     if (fDoRightIndex) wid= fIndexWidth else wid= 0;
  579.     this->SetColWidth( 2+fBasesPerLine+1, 1, wid);
  580.     if (fDoRightName) wid= fNameWidth else wid= 0;
  581.     this->SetColWidth( 2+fBasesPerLine+2, 1, wid);
  582.     
  583.     //! REMap -- SetRowWidth for just about each row...........
  584.  
  585.         // 11 rows for all options per seq. line 
  586.     numLinesPerSeq= (fBasesPerLine - 1 + fNBases) / fBasesPerLine;
  587.     linesPerParag= 11; // spacer + 3 pro + seq + index + coseq + 3copro + renzymes 
  588.     atRow= 2; //skip header
  589.     allSeqFrames= fSeqFrame1.IsOn && fSeqFrame2.IsOn && fSeqFrame3->IsOn();
  590.     noSeqFrames= !fSeqFrame1.IsOn && !fSeqFrame2.IsOn && !fSeqFrame3->IsOn();
  591.     if (!(allSeqFrames || noSeqFrames)) {
  592.         doFrame1= fSeqFrame1->IsOn();
  593.         doFrame2= fSeqFrame2->IsOn();
  594.         doFrame3= fSeqFrame3->IsOn();
  595.         }
  596.     allCoFrames= fShowCoseq.IsOn && fCoFrame1.IsOn && fCoFrame2.IsOn && fCoFrame3->IsOn();
  597.     noCoFrames= !fShowCoseq.IsOn && !fCoFrame1.IsOn && !fCoFrame2.IsOn && !fCoFrame3->IsOn();
  598.     if (!(allCoFrames || noCoFrames)) {
  599.         doCoSeq= fShowCoseq->IsOn();
  600.         doCoFrame1= fCoFrame1->IsOn();
  601.         doCoFrame2= fCoFrame2->IsOn();
  602.         doCoFrame3= fCoFrame3->IsOn();
  603.         }
  604.         
  605.     SetVRect( aRect, 1, 50, 1000, 100);
  606.     FOR i= 1 TO numLinesPerSeq){
  607.  
  608.         theRowHeight= fSeqRowHeight;
  609.         if (allSeqFrames) {
  610.             SetRowHeight( atRow, 5, theRowHeight); 
  611.             atRow= atRow+5;
  612.             }        else if (noSeqFrames) {
  613.             SetOneRow( atRow, TRUE);  //Spacer
  614.             SetRowHeight( atRow, 3, 0); 
  615.             atRow= atRow+3;
  616.             SetOneRow( atRow, TRUE);  //fSeq
  617.             }        else {
  618.             SetOneRow( atRow, TRUE);  //Spacer
  619.             SetOneRow( atRow, doFrame1); 
  620.             SetOneRow( atRow, doFrame2); 
  621.             SetOneRow( atRow, doFrame3); 
  622.             SetOneRow( atRow, TRUE);  //fSeq
  623.             }
  624.         
  625.         SetOneRow( atRow, fDoTopIndex);
  626.         
  627.         if (allCoFrames) {
  628.             SetRowHeight( atRow, 4, theRowHeight); 
  629.             atRow= atRow+4;
  630.             }        else if (noCoFrames) {
  631.             SetRowHeight( atRow, 4, 0); 
  632.             atRow= atRow+4;
  633.             }        else {
  634.             SetOneRow( atRow, doCoSeq); 
  635.             SetOneRow( atRow, doCoFrame1); 
  636.             SetOneRow( atRow, doCoFrame2); 
  637.             SetOneRow( atRow, doCoFrame3); 
  638.             }
  639.         
  640.         startbase= fBasesPerLine * (i-1); //?? 0 or 1 origin
  641.         endbase= startbase + fBasesPerLine - 1;
  642.         this->DrawZymeLine( 3, startBase, endBase, aRect, FALSE, theRowHeight);
  643.         SetOneRow( atRow, TRUE);  //Enzymes...
  644.         }
  645.     
  646.     AddTables();
  647.     
  648. }
  649.  
  650.  
  651. CONST     kMaxZymeWidth ==  9;  
  652.  
  653. pascal void TREMapView::AllZymeTabRows( Integer VAR nRows, rowHeight)
  654. VAR    nzymes, ncols: integer;
  655.         fontinfo        fi ;
  656. {
  657.     if ((fAllzymes->IsOn())) {
  658.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  659.         GetFontInfo(fi);
  660.         rowHeight= 1 + fi.ascent + fi.descent + fi.leading;
  661.         }
  662.     else rowHeight= 0;
  663.     nzymes= fREMap->fREnzymes->GetSize();
  664.     ncols= fBasesPerLine / kMaxZymeWidth; 
  665.     nRows= ((nzymes+ncols-1) / ncols) + 3; /*+ header + footer*2 */    
  666. }
  667.  
  668. pascal void TREMapView::AllZymeTable( integer atRow, VRect aRect)
  669. CONST
  670.         kFontDescent == 2;
  671. VAR        
  672.         integer        h, v, zymesPerCol, rowHeight, nzymes, ncols, nrows;
  673.         fi    : fontinfo;
  674.         
  675.     pascal void DrawHeader( integer h, v)
  676.     {    
  677.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  678.         //- TextSize(12); 
  679.         TextFace([bold]);  
  680.         moveto(h, v);
  681.         DrawString('Site usage for all enzymes');
  682.         v= v + kFontDescent; //fi.descent;
  683.         moveto(h, v);
  684.         Line( fBaseWidth * fBasesPerLine, 0);
  685.     }
  686.     
  687.     pascal void DrawFooter( integer h, v)
  688.     str255        VAR  aLine;
  689.     {    
  690.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  691.         moveto(h, v);
  692.         DrawString('Total number of cuts: ');
  693.         NumToString( fREMap->fCutCount, aLine);
  694.         DrawString( aLine);
  695.     }
  696.  
  697.     pascal void DrawInfoLine( integer h, v)
  698.     VAR  
  699.             str255        aLine;
  700.             integer        i, tab, atZyme, numTab, chleft ;
  701.             aZyme    : TREnzyme;
  702.             
  703.         pascal void drawInfo( TREnzyme zyme)
  704.         {
  705.             NumToString( zyme->fCutCount, aLine);
  706.             moveto( chleft+numTab-StringWidth(aLine), v);
  707.             DrawString(aLine);
  708.             aLine= zyme->fName;
  709.             moveto( chleft+numTab+5, v);
  710.             DrawString(aLine);
  711.         }
  712.     
  713.     {
  714.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  715.         numTab= 2*fBaseWidth;
  716.         chleft= h;
  717.         tab= kMaxZymeWidth * fBaseWidth;
  718.         atZyme= atRow;
  719.         FOR i= 1 to ncols){
  720.             //- atZyme= atRow + i*zymesPerCol;
  721.             if (atZyme<= nzymes) {
  722.                 aZyme= TREnzyme( fREMap->fREnzymes->At( atZyme)); 
  723.                 if ((aZyme!=NULL)) drawInfo( aZyme);
  724.                 }
  725.             atZyme= atZyme + zymesPerCol;
  726.             chleft= chleft + tab;
  727.             }
  728.     }
  729.     
  730.     
  731. {
  732.     /*- this->AllZymeTabRows( nrows, rowHeight);*/ 
  733.     nzymes= fREMap->fREnzymes->GetSize();
  734.     ncols    = fBasesPerLine / kMaxZymeWidth; 
  735.     zymesPerCol= (nzymes+ncols-1) / ncols;    
  736.     GetFontInfo(fi);
  737.     rowHeight= fi.ascent + fi.descent + fi.leading;
  738.     h= aRect.left;
  739.     //- v= aRect.top + fi.ascent; 
  740.     v= aRect.bottom - kFontDescent; //??
  741.     
  742.     if ((atRow<1))
  743.         DrawHeader( h, v)
  744.     else if ((atRow=zymesPerCol+1))
  745.         DrawFooter( h, v)
  746.     else if ((atRow <= zymesPerCol))
  747.         DrawInfoLine( h, v);
  748. }
  749.  
  750.  
  751. pascal void TREMapView::NocuttersRows( Integer VAR nRows, rowHeight)
  752. VAR
  753.         fontinfo        fi;
  754.         longint        nzymes, ncols;
  755. {
  756.     if ((fNoncutters->IsOn())) {
  757.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  758.         GetFontInfo(fi);
  759.         rowHeight= 1 + fi.ascent + fi.descent + fi.leading;
  760.         }
  761.     else rowHeight= 0;
  762.     nzymes= Max( 0, fREMap->fREnzymes.GetSize - fREMap->fCuttersCount);
  763.     ncols    = fBasesPerLine / kMaxZymeWidth; 
  764.     nRows= ((nzymes+ncols-1) / ncols) + 3;    
  765. }
  766.  
  767.  
  768. pascal void TREMapView::NocuttersTab( integer atRow, VRect aRect)
  769. CONST
  770.         kFontDescent == 2;
  771. VAR        
  772.             integer        h, v, zymesPerCol, totalzymes, rowHeight, nzymes, ncols, nrows;
  773.             fi    : fontinfo;
  774.         
  775.     pascal void DrawHeader( integer h, v)
  776.     {    
  777.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  778.         //- TextSize(12); 
  779.         TextFace([bold]);  
  780.         moveto(h, v);
  781.         DrawString('Enzymes that did not cut');
  782.         v= v + kFontDescent; //fi.descent;
  783.         moveto(h, v);
  784.         Line( fBaseWidth * fBasesPerLine, 0);
  785.     }
  786.     
  787.     pascal void DrawFooter( integer h, v)
  788.     {    
  789.  
  790.     }
  791.  
  792.     pascal void DrawInfoLine( integer h, v)
  793.     VAR  
  794.             str255        aLine;
  795.             integer        izyme,  kzyme, i, tab, atZyme, numTab, chleft ;
  796.             aZyme    : TREnzyme;
  797.             okay    : boolean;
  798.             
  799.         pascal void drawInfo( TREnzyme zyme)
  800.         {
  801.             if ((zyme->fCutCount=0)) {
  802.                 moveto( chleft, v);
  803.                 aLine= zyme->fName;
  804.                 DrawString(aLine);
  805.                 }
  806.         }
  807.     
  808.     {
  809.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  810.         numTab= 2*fBaseWidth;
  811.         chleft= h;
  812.         tab= kMaxZymeWidth * fBaseWidth;
  813.         atZyme= atRow;
  814.         iZyme = atZyme-1;
  815.         kZyme = atRow;
  816.         FOR i= 0 to ncols-1){
  817.             atZyme= atRow + i*zymesPerCol; 
  818.             do {
  819.                 aZyme= TREnzyme( fREMap->fREnzymes->At( kZyme)); 
  820.                 if ((aZyme!=NULL) && (aZyme->fCutCount=0)) {
  821.                     iZyme= iZyme+1;
  822.                     okay= (iZyme == atZyme);
  823.                     }                else 
  824.                     okay= FALSE;
  825.                 kZyme= kZyme+1;
  826.             } while (!(okay || (kZyme > totalzymes)));
  827.             if (okay) {
  828.                 drawInfo( aZyme);
  829.                 chleft= chleft + tab;
  830.                 }
  831.             }
  832.     }
  833.     
  834. {
  835.     ncols    = fBasesPerLine / kMaxZymeWidth; 
  836.     this->NocuttersRows( nrows, rowHeight);  
  837.     //- zymesPerCol= nrows - 3;
  838.     totalzymes= fREMap->fREnzymes->GetSize();
  839.     nzymes= Max( 0, totalzymes - fREMap->fCuttersCount); 
  840.     zymesPerCol= (nzymes+ncols-1) / ncols;     
  841.     GetFontInfo(fi);
  842.     h= aRect.left;
  843.     //- v= aRect.top + fi.ascent; 
  844.     v= aRect.bottom - kFontDescent;
  845.     
  846.     if ((atRow<1))
  847.         DrawHeader( h, v)
  848.     else if ((atRow=zymesPerCol+1))
  849.         DrawFooter( h, v)
  850.     else if ((atRow <= zymesPerCol))
  851.         DrawInfoLine( h, v);
  852. }
  853.  
  854.  
  855.  
  856.  
  857. pascal void TREMapView::CutpointsRows( Integer VAR nRows, rowHeight)
  858. {
  859.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  860.     if ((fCutpoints->IsOn())) rowHeight= cHeight
  861.     else rowHeight= 0;
  862.     nRows= 4;
  863. }
  864.  
  865. pascal void TREMapView::CutpointsTab( integer atRow, VRect aRect)
  866. CONST
  867.         kFontDescent == 2;
  868. VAR
  869.         integer        zymesPerCol, nrows, rowHeight, h, v, ncols ;
  870.         fontInfo        fi ;
  871.         
  872.     pascal void DrawHeader( integer h, v)
  873.     {    
  874.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  875.         TextFace([bold]);  
  876.         moveto(h, v);
  877.         DrawString('Cut points by enzyme');
  878.         v= v + kFontDescent; //fi.descent;
  879.         moveto(h, v);
  880.         Line( fBaseWidth * fBasesPerLine, 0);
  881.     }
  882.     
  883.     pascal void DrawFooter( integer h, v)
  884.     {    
  885.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  886.         moveto(h, v);
  887.         DrawString('--- not ready yet ---');
  888.     }
  889.     
  890.     pascal void DrawInfoLine( integer h, v)
  891.     {
  892.     }
  893.  
  894. {
  895.     ncols    = fBasesPerLine / kMaxZymeWidth; 
  896.     this->CutpointsRows( nrows, rowHeight);  
  897.     zymesPerCol= nrows - 4; 
  898.     GetFontInfo(fi);
  899.     //- rowHeight= fi.ascent + fi.descent + fi.leading; 
  900.     h= aRect.left;
  901.     //- v= aRect.top + fi.ascent; 
  902.     v= aRect.bottom - kFontDescent; //??
  903.     
  904.     if ((atRow<1))
  905.         DrawHeader( h, v)
  906.     else if ((atRow=zymesPerCol+1))
  907.         DrawFooter( h, v)
  908.     else if ((atRow <= zymesPerCol))
  909.         DrawInfoLine( h, v);
  910.  
  911. }
  912.  
  913.  
  914.  
  915. pascal void TREMapView::DrawZymeLine( integer startCellh, startBase, endbase, VRect aRect,
  916.                                                                      Boolean        doDraw; Integer VAR lineHeight)
  917. /*==== 
  918.         gctcggctgctgctcggctg
  919.                 ||        | ||
  920.              abcI    cbaII
  921.                                     hcgX
  922. ====*/
  923. VAR
  924.         RgnHandle        filledArea, aRgn;
  925.         integer        atbot, cuts, wd, ws, rowbot, lasti, i, j, k;
  926.         Point        at, lat;
  927.         first,overlap    : boolean;
  928.         lastzyme, zymes    : str63;    
  929.         Rect        fillRect, bRect, cRect;
  930.         integer        nameHeight, rowLeft, rowTop, rotBot;
  931.         integer        atcellh, chleft, minCuts,maxCuts, firstCut, nCuts, cutIndx;
  932.         
  933.     pascal void spaceright(void)
  934.     integer        VAR  chright;
  935.     {
  936.         //- chleft= chleft + fBaseWidth; *//* ? bad for wide columns -- use grid cell positions ?
  937.         chright= chleft + GetColWidth(atCellh) - fColInset;
  938.         chleft = chright + fColInset;
  939.         atcellh= atcellh + 1;
  940.     }
  941.  
  942. {
  943.     firstCut= fLastZymeCut;
  944.     fREMap->CutsAtBase( startBase, firstCut, ncuts);    //!? don't care if startbase has no cuts
  945.     cutindx= firstCut;
  946.     
  947.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle/*fZymeStyle*/);  /*$POP
  948.  
  949.     atcellh= startcellh;
  950.     nameHeight= cHeight;
  951.     rowTop= aRect.top;
  952.     rowleft= aRect.left;
  953.     //rowTop= rowTop-4;
  954.     rowBot= rowTop;
  955.     filledArea= newRgn;
  956.     aRgn= newRgn;
  957.     if ((fMincuts!=NULL)) minCuts= fMinCuts.GetValue else minCuts= 1; //-1?
  958.     if ((fMaxcuts!=NULL)) maxCuts= fMaxCuts.GetValue else maxCuts= maxint; //-1?
  959.     
  960.     chleft= rowLeft + kNucSpace;
  961.     SetRect( fillRect, chleft, rowTop, chleft+1, rowTop+1);
  962.     RectRgn( filledArea, fillRect); //must start w/ non-empty rgn
  963.     MoveTo( chleft, rowTop);
  964.     FOR i= startBase TO endbase){
  965.         
  966.         while ( (*fCutList)^[cutindx].fSeqindex < i do cutindx= cutindx+1;  
  967.         first= TRUE;
  968.         lasti= -1; lastzyme= '';
  969.         while ( (*fCutList)^[cutindx].fSeqindex == i do {
  970.             zymes= (*fCutList)^[cutindx].fREnzyme->fName;
  971.             cuts= (*fCutList)^[cutindx].fREnzyme->fCutcount;
  972.             cutindx= cutindx+1;
  973.             if ((cuts < minCuts) || (cuts > maxCuts)) LEAVE;
  974.             //! Kludge til we fix REMap to stop dups
  975.             if ((i=lasti) && (zymes == lastzyme)) LEAVE /*While*/; 
  976.             lasti= i; lastzyme= zymes;
  977.             
  978.             if (first) {
  979.                 MoveTo( chleft, rowTop);
  980.                 if (doDraw) Line( 0, 2/*kTicSize*/) else Move( 0, 2);
  981.                 }
  982.             ws= StringWidth( zymes);
  983.             wd= 2 + ws div 2;
  984.             do {
  985.                 GetPen( at);
  986.                 SetRect( cRect, at.h-wd, at.v, at.h+wd, at.v+nameHeight);
  987.                 overlap= RectInRgn( cRect, filledArea); 
  988.             
  989.                 if (doDraw && overlap && !first) {
  990.                     //!? replace this w/ draw top to bottom of line, then overwrite zyme names 
  991.                     SetRect( bRect, at.h, at.v-nameHeight, at.h+1, at.v);
  992.                     if (!RectInRgn( bRect, filledArea)) {
  993.                         MoveTo( chleft, at.v-nameHeight+1);
  994.                         Line( 0, nameHeight-1);
  995.                         }
  996.                     }
  997.                 first= FALSE;
  998.                 MoveTo( chleft, at.v+nameHeight);
  999.             } while (!(!overlap));
  1000.     
  1001.             RectRgn( aRgn, cRect);
  1002.             UnionRgn(filledArea, aRgn, filledArea);
  1003.             if (doDraw) {
  1004.                 Move( -(ws div 2), 0);
  1005.                 TextMode(srcCopy);  //erase line overlaps...
  1006.                 DrawString( zymes); 
  1007.                 TextMode(srcOr);
  1008.                 }
  1009.             GetPen( at);
  1010.             rowBot = max( rowBot, at.v);   
  1011.             }
  1012.             
  1013.         spaceright();
  1014.         }
  1015.     lineHeight= rowbot - rowtop + 10; /* + fudge factor*/    
  1016.     DisposeRgn( filledArea);
  1017.     DisposeRgn( aRgn);
  1018. }
  1019.  
  1020.  
  1021.  
  1022. pascal void TREMapView::DrawRangeOfCells(GridCell startCell, stopCell, VRect aRect) 
  1023.                                         // override 
  1024. VAR
  1025.         short        colWidth;
  1026.         short        rowHeight;
  1027.         short        i, j;
  1028.         GridCell        aCell;
  1029.         short        left;
  1030.     
  1031.         lineKind, startBase, endBase,
  1032.         Integer        linesPerParag, dummy, seqLine, atBase;
  1033.  
  1034.  
  1035.     pascal void DrawHeader(void)
  1036.     VAR
  1037.         h, v    : integer;
  1038.         s, s1    : str255;
  1039.         longint        daytime;
  1040.         Rect        pagerect;
  1041.         
  1042.         pascal void nextLine( str255 s)
  1043.         {
  1044.             WITH pagerect)h= (right + left - stringwidth(s)) / 2;
  1045.             v= v + cHeight + 4; //! CHeight is a UPlot funct !
  1046.             MoveTo(h,v);
  1047.             DrawString(s);
  1048.         }
  1049.             
  1050.     {
  1051.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  1052.         GetQDExtent( pagerect);
  1053.         v= pagerect.top;
  1054.         TextSize(14);
  1055.         nextline( concat('Restriction Map of ', fSeq->fName));
  1056.  
  1057.         //Stat line: fSeq->fLength, fMincuts->GetValue(), fMaxcuts.GetValue 
  1058.         TextSize(10);
  1059.         getDateTime( daytime);
  1060.         iuDateString( daytime, abbrevDate, s);
  1061.         iuTimeString( daytime, FALSE,  s1);
  1062.         nextline( concat(s,'  ',s1));                
  1063.     }
  1064.  
  1065. {
  1066.     laserLine( 2, 4); // set laserline smaller ...
  1067.  
  1068.     linesPerParag= 11; // spacer + 3 pro + seq + index + coseq + 3copro + renzymes 
  1069.     seqLine= (startCell.v-1) / linesPerParag;
  1070.     atBase = max( 0, startCell.h-3) + fFirstBase + min( fNbases, seqline * fBasesPerLine);
  1071.     fLastZymeCut= atBase;
  1072.     
  1073.     if (startCell.v == 1) DrawHeader;
  1074.     
  1075.     //- inherited::DrawRangeOfCells( startCell, stopCell, aRect); 
  1076.     //......... copy of UGricView.inc1.p:DrawRangeOfCells() .........
  1077.     aRect.left = aRect.left + ((fColInset) >> 1);    // fColInset / 2 
  1078.     aRect.top = aRect.top + ((fRowInset) >> 1);     // fRowInset / 2 
  1079.     left = aRect.left;
  1080.  
  1081.     if (fColWidths->fNoOfChunks == 1) colWidth = GetColWidth(1);
  1082.     if (fRowHeights->fNoOfChunks == 1) rowHeight = GetRowHeight(1);
  1083.  
  1084.     FOR j = startCell.v TO stopCell.v){
  1085.         if (fRowHeights->fNoOfChunks == 1)             // only one height 
  1086.             aRect.bottom = aRect.top + rowHeight - fRowInset
  1087.         else
  1088.             aRect.bottom = aRect.top + GetRowHeight(j) - fRowInset;
  1089.  
  1090.         aRect.left = left;                            // start back at the left for the next row 
  1091.         lineKind= (j-1) % linesPerParag;
  1092.         
  1093.         if ((j>= fAllZymesStart) && (j <= fAllZymesEnd)) {
  1094.             if ((fAllzymes->IsOn())) this->AllZymeTable(j-fAllZymesStart, aRect);
  1095.             }        else if ((j>= fNoCutsStart) && (j <= fNoCutsEnd)) {
  1096.             if ((fNoncutters->IsOn())) this->NoCuttersTab(j-fNoCutsStart, aRect);
  1097.             }        else if ((j>= fCutPointStart) && (j <= fCutPointEnd)) {
  1098.             if ((fCutpoints->IsOn())) this->CutpointsTab(j-fCutPointStart, aRect);
  1099.             }            
  1100.         else if (((j>1) && (lineKind=0))) { //zyme line
  1101.              i= startCell.h;
  1102.              while ( i < 3){ //scoot over to zyme start...
  1103.                 aRect.right= aRect.left + GetColWidth(i) - fColInset;
  1104.                 aRect.left = aRect.right + fColInset;
  1105.                 i= i+1;
  1106.                 }
  1107.             seqLine = (j-2) / linesPerParag; //! j-2 to get zymes on right line
  1108.                 /*! could get in trouble here -- need to draw full line for positioning, but
  1109.                  aRect &/or startCell.h may be inset from start of line...*/
  1110.             startBase= max(0, i - 3) + fFirstBase + min( fNbases, seqline * fBasesPerLine);
  1111.             endBase= startBase + min(fBasesPerLine-1, stopCell.h - i);
  1112.             this->DrawZymeLine( i, startBase, endBase, aRect, TRUE, dummy);
  1113.             }            
  1114.         else { // ... original code
  1115.             FOR i = startCell.h TO stopCell.h){
  1116.                 if (fColWidths->fNoOfChunks == 1)            // only one height 
  1117.                     aRect.right = aRect.left + colWidth - fColInset
  1118.                 else
  1119.                     aRect.right = aRect.left + GetColWidth(i) - fColInset;
  1120.     
  1121.                 aCell.h = i;
  1122.                 aCell.v = j;
  1123.                 DrawCell(aCell, aRect);
  1124.     
  1125.                 aRect.left = aRect.right + fColInset;
  1126.                 }
  1127.             }
  1128.             
  1129.         aRect.top = aRect.bottom + fRowInset;
  1130.         }
  1131. }
  1132.  
  1133.  
  1134.  
  1135. pascal void TREMapView::DrawCell(GridCell aCell, VRect aRect) // override 
  1136. CONST
  1137.     kFontDescent == 2;
  1138.     kIndexRise == 1;
  1139. VAR
  1140.     integer        lineKind, linesPerParag ;
  1141.     longint        atBase, atBase1, atSeq, seqLine ;    
  1142.     Boolean        doTopIndex, doSequence;
  1143.     VRect        subRect;
  1144.     Boolean        threeBase;
  1145.     
  1146. /*!! aRect is band w/ all lines associated w/ sequence - base, index,
  1147.         prot[1-3], coprot[1-3], and zyme(s)
  1148.         ? make aRect == fSeqRowHeight high, and shift aRect down for each sub-line
  1149. --*/
  1150.  
  1151.     pascal void drawTopIndex( longint atBase, boolean toptic, bottic)  
  1152.     VAR  nums    : str255;
  1153.              integer        chRight, chLeft, rowtop, ws;
  1154.     {
  1155.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  1156.         chleft    = subRect.left;
  1157.         chRight    = chleft + fBaseWidth; //fix for extra spacers
  1158.         rowtop    = subRect.bottom-kIndexRise;  
  1159.         MoveTo( chleft+kNucSpace, rowtop);
  1160.         if ((atBase % 10 == 4)) {
  1161.             if ((bottic)) Line(0,-1) else Move(0,-1);
  1162.             NumToString( atBase+1, nums);
  1163.             ws= StringWidth(nums);
  1164.             Move( -ws / 2, -1);
  1165.             DrawString(nums);
  1166.             if ((toptic)) {
  1167.                 MoveTo( chleft+kNucSpace, rowtop);
  1168.                 Line(0,2);
  1169.                 }
  1170.             }
  1171.         /*---
  1172.         else if ((atBase % 10 == 9)) {
  1173.             if ((bottic)) Line(0,-2);
  1174.             if ((toptic)) {
  1175.                 MoveTo( chleft+kNucSpace, rowTop);
  1176.                 Line(0,2);
  1177.                 }
  1178.             }
  1179.         ---*/
  1180.         MoveTo( chleft, rowtop);
  1181.         LineTo( chright, rowtop);
  1182.     }
  1183.  
  1184.     pascal void drawSideIndex(longint atBase, leftBorder)
  1185.     str255        VAR  nums ;
  1186.     {
  1187.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNumStyle);  /*$POP
  1188.         MoveTo( subRect.right-leftBorder, subRect.bottom-kFontDescent);
  1189.         NumToString( atBase+1, nums);
  1190.         Move( -StringWidth(nums), 0);
  1191.         DrawString(nums);
  1192.     }
  1193.  
  1194.     pascal void DrawName( integer rightBorder, longint atBase)
  1195.     VAR     aName    : Str63;
  1196.                 aSeq    : TSequence;
  1197.     {
  1198.         aSeq= fSeq;
  1199.         if (aSeq!=NULL) {
  1200.     //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  1201.             MoveTo( subRect.left+rightBorder, subRect.bottom-kFontDescent);
  1202.             aName= aSeq->fName;
  1203.             DrawString(aName);
  1204.             } 
  1205.     }
  1206.     
  1207.     pascal void DrawWord( str63 word, integer rightBorder, longint atBase)
  1208.     {
  1209.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle);  /*$POP
  1210.         MoveTo( subRect.left+rightBorder, subRect.bottom-kFontDescent);
  1211.         DrawString(word);
  1212.     }
  1213.  
  1214.     pascal void DrawNuc( longint atBase, TSequence aSeq)
  1215.     VAR
  1216.          integer        rowbot, cw, rowleft;
  1217.         hSeq        : CharsHandle;
  1218.         ch            : char;
  1219.         myRect    : VRect;
  1220.     {
  1221.         if (aSeq!=NULL) {
  1222.         //$PUSH*/ /*$H-*/ SetPortTextStyle(fBaseStyle);  /*$POP
  1223.             rowleft= subRect.left;
  1224.             rowbot = subRect.bottom - kFontDescent;  
  1225.             myRect= subRect;
  1226.             myRect.right= myRect.left + fBaseWidth; //fix for extra spacers
  1227.             handle(hSeq)= aSeq->fBases;
  1228.             ch= (*hSeq)^[atBase];
  1229.             if (ch == indelSoft) then ch= indelHard; //look better for output...
  1230.  
  1231.             if (fUseColor) CASE ch OF
  1232.                 'A','a': RGBForeColor( gAcolor);
  1233.                 'C','c': RGBForeColor( gCcolor);
  1234.                 'G','g': RGBForeColor( gGcolor);
  1235.                 'T','t',
  1236.                 'U','u': RGBForeColor( gTcolor);
  1237.                 otherwise
  1238.                                  RGBForeColor( gNcolor);
  1239.                 }            else
  1240.                 RGBForeColor( gNcolor);
  1241.                                                 
  1242.             cw= (fBaseWidth - charwidth(ch)) / 2;
  1243.             MoveTo( rowleft+cw, rowbot);
  1244.             DrawChar(ch);
  1245.             TextMode(srcOr); //? srcOr/srcCopy
  1246.             }
  1247.     }  
  1248.     
  1249.     
  1250.     pascal void DrawProt( integer atBase,  boolean use3aa, frame: integer; charsHandle hSeq)
  1251.     //for frame in [1..3] use seq[0+frame-1..end] 
  1252.     VAR
  1253.         integer        cw, atFrame;
  1254.         char        ch ;
  1255.     {
  1256.         frame= frame-1; //make 0-relative
  1257.         atFrame= atBase % 3;
  1258.         if ((atFrame == frame) && (hSeq!=NULL)) {
  1259.             //! atBase= (atBase / 3) * 3 + frame; *//*<< don't need: locate proper aa index
  1260.     
  1261.             /*$PUSH*/ /*$H-*/ SetPortTextStyle(fBaseStyle);  /*$POP*/    
  1262.             ch= (*hSeq)^[atBase];
  1263.             cw= (fBaseWidth - charwidth(ch)) / 2;
  1264.             MoveTo( subRect.left+cw,  subRect.bottom - kFontDescent);
  1265.             if (use3aa) DrawString(Amino123(ch)) else DrawChar(ch);
  1266.             }
  1267.     }  
  1268.     
  1269.     
  1270.     pascal void DrawZymes( integer atBase)
  1271.             /*==== 
  1272.                     gctcggctgctgctcggctg
  1273.                             ||        | ||
  1274.                          abcI    cbaII
  1275.                                                 hcgX
  1276.             ====*/
  1277.     VAR
  1278.             RgnHandle        filledArea,aRgn;
  1279.             rowTop, chLeft, cutindx, firstCut, nCuts,
  1280.             integer        cuts, wd, ws, lasti, i, j, k;
  1281.             Point        at, lat;
  1282.             first, overlap    : boolean;
  1283.             lastzyme, zymes    : str63;    
  1284.             Rect        fillRect,bRect,aRect;
  1285.             
  1286.             nameHeight,
  1287.             integer        minCuts, maxCuts; //make these object fields...
  1288.  
  1289.     {
  1290.         firstCut= fLastZymeCut;
  1291.         fREMap->CutsAtBase( atBase, firstCut, ncuts);    
  1292.         fLastZymeCut= firstCut; //?
  1293.         if (nCuts > 0) {
  1294.             /*$PUSH*/ /*$H-*/ SetPortTextStyle(fNameStyle/*fZymeStyle*/);  /*$POP*/    
  1295.             rowTop= subRect.top-4;
  1296.             chleft= subRect.left+kNucSpace;
  1297.             if ((fMincuts!=NULL)) minCuts= fMinCuts.GetValue else minCuts= 1; //-1?
  1298.             if ((fMaxcuts!=NULL)) maxCuts= fMaxCuts.GetValue else maxCuts= maxint; //-1?
  1299.             nameHeight= cHeight;
  1300.             first= TRUE;
  1301.             lasti= -1; 
  1302.             lastzyme= '';
  1303.             
  1304.             filledArea= newRgn;
  1305.             aRgn= newRgn;
  1306.             SetRect( fillRect, chleft, rowTop, chleft+1, rowTop+1);
  1307.             RectRgn( filledArea, fillRect); //must start w/ non-empty rgn
  1308.     
  1309.             cutindx= firstCut;
  1310.             while ( (*fCutList)^[cutindx].fSeqindex == atBase do {
  1311.                 zymes= (*fCutList)^[cutindx].fREnzyme->fName;
  1312.                 cuts= (*fCutList)^[cutindx].fREnzyme->fCutcount;
  1313.                 cutindx= cutindx+1;
  1314.                 if ((cuts < minCuts) || (cuts > maxCuts)) LEAVE;
  1315.                 //! Kludge til we fix REMap to stop dups
  1316.                 if ((atBase=lasti) && (zymes == lastzyme)) LEAVE /*While*/; 
  1317.                 lasti= atBase; 
  1318.                 lastzyme= zymes;
  1319.                 
  1320.                 if (first) {
  1321.                     MoveTo( chleft, rowTop);
  1322.                     Line( 0, 2 /*kTicSize*/); 
  1323.                     }
  1324.                 ws= StringWidth( zymes);
  1325.                 wd= 2 + ws div 2;
  1326.                 do {
  1327.                     GetPen( at);
  1328.                     SetRect( aRect, at.h-wd, at.v, at.h+wd, at.v+nameHeight);
  1329.                     overlap= RectInRgn( aRect, filledArea); 
  1330.                 
  1331.                     if (overlap && !first) {
  1332.                         SetRect( bRect, at.h, at.v-nameHeight, at.h+1, at.v);
  1333.                         if (!RectInRgn( bRect, filledArea)) {
  1334.                             MoveTo( chleft, at.v-nameHeight+1);
  1335.                             Line( 0, nameHeight-1);
  1336.                             }
  1337.                         }
  1338.                     first= FALSE;
  1339.                     MoveTo( chleft, at.v+nameHeight);
  1340.                 } while (!(!overlap));
  1341.         
  1342.                 RectRgn( aRgn, aRect);
  1343.                 UnionRgn(filledArea, aRgn, filledArea);
  1344.                 Move( -(ws div 2), 0);
  1345.                 TextMode(srcCopy);  //erase line overlaps...
  1346.                 DrawString( zymes); 
  1347.                 TextMode(srcOr);
  1348.                 GetPen( at);
  1349.                 }
  1350.                             
  1351.             DisposeRgn( filledArea);
  1352.             DisposeRgn( aRgn);
  1353.             }
  1354.     }
  1355.  
  1356.     
  1357. {
  1358.     if ((aRect.bottom < aRect.top+2)) exit(DrawCell);
  1359.  
  1360.     if ((aCell.v == 1)) { //header line
  1361.         //nada -- don't want to draw header for each of 44 CELLs in the header line
  1362.         }    else if ((aCell.v >= fAllZymesStart)) {
  1363.         //nada -- tables
  1364.         }    else {
  1365.         subRect= aRect;
  1366.         linesPerParag= 11; // spacer + 3 pro + seq + index + coseq + 3copro + renzymes 
  1367.         lineKind= (aCell.v-1) % linesPerParag;
  1368.         seqLine = (aCell.v-1) / linesPerParag; //!? (aCell.v-2) for enz line !?
  1369.         /* atBase equation depends on if in seq or on sides */ 
  1370.         threeBase= (fThreeBase!=NULL) && (fThreeBase->IsOn());
  1371.  
  1372.         if ((aCell.h == 1)) { //nameleft
  1373.             atBase= fFirstBase + min( fNbases, seqLine * fBasesPerLine);
  1374.             if (fDoLeftName) CASE lineKind OF
  1375.                 1 : ; //spacer
  1376.                 2 : DrawWord( 's1', 0, atBase);
  1377.                 3 : DrawWord( 's2', 0, atBase);
  1378.                 4 : DrawWord( 's3', 0, atBase);
  1379.                 5 : DrawName( 0, atBase);
  1380.                 7 : DrawWord( 'cmp.', 0, atBase);
  1381.                 8 : DrawWord( 'c1', 0, atBase);
  1382.                 9 : DrawWord( 'c2', 0, atBase);
  1383.                 10: DrawWord( 'c3', 0, atBase);
  1384.                 0 : DrawWord( 'enz.', 0, atBase);
  1385.                 }
  1386.             }            
  1387.         else if ((aCell.h == 2)) { //indexLeft
  1388.             atBase= fFirstBase + min( fNbases, seqLine * fBasesPerLine);
  1389.             if (fDoLeftIndex) CASE lineKind OF
  1390.                 5 : DrawSideIndex( atBase, kNucBorder);
  1391.                 }
  1392.             }            
  1393.         else if ((aCell.h < fBasesPerLine+3)) { //bases
  1394.             atBase1= (seqLine * fBasesPerLine) + aCell.h - 2;
  1395.             if ((atBase1 <= fNBases)) {
  1396.                 atBase= fFirstBase - 1 + atBase1;     //atbase == 0  for first 
  1397.                 switch (lineKind) {
  1398.                     1 : ; //spacer
  1399.                     2, 3, 4 : if ((atBase1 <= fNBases-2)) 
  1400.                             DrawProt( atBase, ThreeBase, lineKind-1, fProt);
  1401.                     5 : DrawNuc( atBase, fSeq);
  1402.                     6 : DrawTopIndex( atBase, TRUE, TRUE); //?? - orig was above fSeq, below fCoseq or here depending on others
  1403.                     7 : DrawNuc( atBase, fREMap->fCoSeq);
  1404.                     8, 9, 10: if ((atBase1 <= fNBases-2)) 
  1405.                             DrawProt( atBase, ThreeBase, lineKind-7, fCoProt);
  1406.                     0 : ; //- DrawZymes( atBase);
  1407.                     }
  1408.                 }
  1409.             }            
  1410.         else if ((aCell.h == fBasesPerLine+3)) { //indexRight
  1411.             atBase= fFirstBase - 1 + min( fNBases, (seqLine+1) * fBasesPerLine);
  1412.             if (fDoRightIndex) CASE lineKind OF
  1413.                 5 : DrawSideIndex( atBase, 0);
  1414.                 }
  1415.             }        else if ((aCell.h == fBasesPerLine+4)) { //nameRight
  1416.             atBase= fFirstBase - 1 + min( fNBases, (seqLine+1) * fBasesPerLine);
  1417.             if (fDoRightName) CASE lineKind OF
  1418.                 1 : ; //spacer
  1419.                 2 : DrawWord( 's1', kNucBorder, atBase);
  1420.                 3 : DrawWord( 's2', kNucBorder, atBase);
  1421.                 4 : DrawWord( 's3', kNucBorder, atBase);
  1422.                 5 : DrawName( kNucBorder, atBase);
  1423.                 7 : DrawWord( 'cmp.', kNucBorder, atBase);
  1424.                 8 : DrawWord( 'c1', kNucBorder, atBase);
  1425.                 9 : DrawWord( 'c2', kNucBorder, atBase);
  1426.                 10: DrawWord( 'c3', kNucBorder, atBase);
  1427.                 0 : DrawWord( 'enz.', kNucBorder, atBase);
  1428.                 }
  1429.             }
  1430.     }
  1431. }
  1432.  
  1433.  
  1434.  
  1435. pascal void TREMapView::CalcMinFrame(VRect VAR minFrame)
  1436. {
  1437.     inherited::CalcMinFrame( minFrame);
  1438. }
  1439.  
  1440.  
  1441.  
  1442.  
  1443. pascal void TREMapView::DoMenuCommand(CommandNumber aCommandNumber) // override 
  1444. {
  1445.     switch (aCommandNumber) {
  1446.         cCopy: {
  1447.                 this->WriteToDeskScrap(); 
  1448.                 gClipboardMgr->CheckDeskScrap(); //! this notifies app of changed scrap 
  1449.                 }
  1450.         otherwise
  1451.             inherited::DoMenuCommand(aCommandNumber);
  1452.         }
  1453. }
  1454.  
  1455.  
  1456.  
  1457. /*******
  1458. pascal TCommand TREMapView::DoMouseCommand(Point VAR theMouse, EventInfo VAR info,
  1459.                                    Point VAR hysteresis)
  1460. VAR
  1461.         FailInfo        fi;
  1462.  
  1463.     pascal void HdlInitCmdFailed(OSErr error, long message)
  1464.         {
  1465.         FreeIfObject(protoREMap);
  1466.         protoREMap = NULL;
  1467.         }
  1468.  
  1469.     {                    
  1470.     DoMouseCommand = NULL;
  1471.  
  1472.     fClickPt = theMouse;
  1473.     if (palette->fCurrREMap > 0) { // draw mode
  1474.         FailSpaceIsLow();                                 // Make sure we aren't low on memory 
  1475.  
  1476.         Deselect();
  1477.  
  1478.         //Clone appropriate REMap
  1479.  
  1480.         protoREMap = TREMap(gREMapsArray[palette->fCurrREMap].Clone);
  1481.         FailNil(protoREMap);
  1482.  
  1483.         CatchFailures(fi, HdlInitCmdFailed);
  1484.         // Make sure cloning the REMap left us with enough memory to continue.
  1485.         FailSpaceIsLow();
  1486.  
  1487.         New(REMapSketcher);
  1488.         FailNil(REMapSketcher);
  1489.         REMapSketcher->IREMapSketcher(this, protoREMap, info.theOptionKey);
  1490.         Success(fi);
  1491.         DoMouseCommand = REMapSketcher;
  1492.         }            
  1493.         
  1494.     else {         //select mode
  1495.         REMapUnderMouse = NULL;
  1496.         fREMapDocument->EachVirtualREMapDo(CheckREMap);
  1497.  
  1498.         if (REMapUnderMouse == NULL)    {        //area select
  1499.             if (!info.theShiftKey)
  1500.                 Deselect();
  1501.             New(REMapSelector);
  1502.             FailNil(REMapSelector);
  1503.             REMapSelector->IREMapSelector(cMouseCommand, this);
  1504.             DoMouseCommand = REMapSelector;
  1505.             } 
  1506.  
  1507.         else {                                        //REMap select/move/...
  1508.             if (!(REMapUnderMouse->fIsSelected || info.theShiftKey))
  1509.                 Deselect();
  1510.  
  1511.             if (info.theShiftKey) {
  1512.                 REMapUnderMouse->fIsSelected = !REMapUnderMouse->fIsSelected;
  1513.                 if (REMapUnderMouse->fIsSelected)
  1514.                     REMapUnderMouse->Highlight(hlOff, hlOn)
  1515.                 else
  1516.                     REMapUnderMouse->Highlight(hlOn, hlOff);
  1517.                 }            else if (!REMapUnderMouse->fIsSelected)
  1518.                 {
  1519.                 REMapUnderMouse->fIsSelected = TRUE;
  1520.                 DoHighlightSelection(hlOff, hlOn);
  1521.                 }
  1522.  
  1523.             if (REMapUnderMouse->fIsSelected) {
  1524.                 New(REMapDragger);
  1525.                 FailNil(REMapDragger);
  1526.                 REMapDragger->IREMapDragger(this);
  1527.                 DoMouseCommand = REMapDragger;
  1528.                 }
  1529.             //else, fall-through, we return NULL
  1530.             }     
  1531.         }                     
  1532. }                                        
  1533. **********/
  1534.  
  1535.  
  1536.  
  1537. pascal void TREMapView::DoSetupMenus(void)
  1538.     {
  1539.         short        i;
  1540.         Boolean        anySelection;
  1541.         Boolean        haveMemory;
  1542.         MenuHandle        aMenuHandle;
  1543.         short        item;
  1544.         Str255        itemName;
  1545.  
  1546.  
  1547.     inherited::DoSetupMenus();
  1548.  
  1549.     anySelection = FALSE;
  1550.     haveMemory = !MemSpaceIsLow;
  1551.  
  1552.     Enable(cCopy, TRUE && haveMemory);
  1553. /*----    
  1554.     Enable(cCut, anySelection && haveMemory);
  1555.     if (haveMemory) CanPaste(kPrintClipType);
  1556.     Enable(cClear, anySelection);
  1557. -------*/
  1558. }             
  1559.  
  1560.